package Test;

import java.util.Calendar;
import java.util.Date;

public class dome5 {
    public static void main(String[] args) {
        Date date1=new Date();
        System.out.println("date1:"+date1);//获取当前时间

        long time=date1.getTime();//将当前时间转换为毫秒值
        System.out.println("time:"+time);

        Date date2=new Date(1641110418166L);//创建一个固定的时间
        System.out.println("date2:"+date2);

        //获取calendar类型的对象
        Calendar calendar=Calendar.getInstance();
        System.out.println("calendar:"+calendar);

        //获取现在的年月日时间
        int year=calendar.get(Calendar.YEAR);
        int mount=calendar.get(Calendar.MONTH);
        int day=calendar.get(Calendar.DATE);
        System.out.println("现在是"+year+"年"+(mount+1)+"月"+day+"日");

        //设置年月日时间
        calendar.set(Calendar.YEAR,2020);
        calendar.set(2020,8,15);
        int year1=calendar.get(Calendar.YEAR);
        int mount1=calendar.get(Calendar.MONTH);
        int day1=calendar.get(Calendar.DATE);
        System.out.println("现在是"+year1+"年"+(mount1+1)+"月"+day1+"日");
    }
}